#pragma rtGlobals=1		// Use modern global access method.


function conv(energy, wG, wL) //for all waves in folder (except energy wave)

wave energy
variable wG, wL
variable midpnt

string allbutenergy= "!" + nameofwave(energy)
string waves = wavelist(allbutenergy,";","")

wave Ewave = energy

variable i
For (i=0; i<itemsinlist(waves); i+=1)

If (strsearch(stringfromlist(i,waves),"_conv",0) == -1 && !stringmatch(stringfromlist(i,waves),"Gwave") && !stringmatch(stringfromlist(i,waves),"Lwave") && !stringmatch(stringfromlist(i,waves),"Vwave") )

wave Dwave = $stringfromlist(i,waves)

midpnt=(Wavemax(Ewave)+Wavemin(Ewave))/2
setscale x,Wavemin(Ewave),wavemax(Ewave), Dwave

Make/O/N=(numpnts(Ewave)) $(nameofwave(Dwave)+"_conv"), Lwave, Gwave, Vwave
wave DOS_conv=$(nameofwave(Dwave)+"_conv")
setscale x,Wavemin(Ewave),Wavemax(Ewave), DOS_conv,Gwave,Lwave,Vwave


Lwave=(wL/2)/((x-midpnt)^2+(wL/2)^2)
Gwave=Exp(-(x-midpnt)^2/(2*(wG/(2*Sqrt(2*Log(2))))^2))
DOS_conv=Dwave


variable SLwave = Sum(Lwave)	//normalize waves
Lwave/=SLwave
variable SGwave = Sum(Gwave)
Gwave/= SGwave


Vwave=Gwave

Convolve/A Lwave Vwave
Convolve/A  Vwave DOS_conv

EndIf

EndFor

end function


function conv1(energy,spectra, wG, wL) //for one wave

wave energy
wave spectra
variable wG, wL
variable midpnt

wave Ewave = energy
wave Dwave = spectra

midpnt=(Wavemax(Ewave)+Wavemin(Ewave))/2
setscale x,Wavemin(Ewave),wavemax(Ewave), Dwave

Make/O/N=(numpnts(Ewave)) $(nameofwave(Dwave)+"_conv"), Lwave, Gwave, Vwave
wave DOS_conv=$(nameofwave(Dwave)+"_conv")
setscale x,Wavemin(Ewave),Wavemax(Ewave), DOS_conv,Gwave,Lwave,Vwave


Lwave=(wL/2)/((x-midpnt)^2+(wL/2)^2)
Gwave=Exp(-(x-midpnt)^2/(2*(wG/(2*Sqrt(2*Log(2))))^2))
DOS_conv=Dwave


variable SLwave = Sum(Lwave)	//normalize waves
Lwave/=SLwave
variable SGwave = Sum(Gwave)
Gwave/= SGwave


Vwave=Gwave

Convolve/A Lwave Vwave
Convolve/A  Vwave DOS_conv

End Function